Skip to content

Fix channels and invalid samples in wfdb_to_wav - #645

Merged
tompollard merged 1 commit into
mainfrom
fix-wfdb-to-wav-followups
Nov 21, 2026
Merged

tompollard merged 1 commit into
mainfrom
fix-wfdb-to-wav-followups

Conversation

@tompollard

Copy link
Copy Markdown
Member

Follow-ups to #632 for wfdb_to_wav. They change the same few lines, so they are in one PR.

  • Read digital samples (wfdb_to_wav: read digital samples directly instead of converting back with adc() #638). The record is read with physical=False, and d_signal is used directly. Before, physical values were read and converted back with adc(). That needed a full-length float64 copy, and the output depended on how adc() rounds. The old comment about the mismatches from that conversion is removed.

  • channels (wfdb_to_wav ignores the channels parameter #640). It is now passed to rdrecord. Before, it was ignored and every signal was written.

  • Invalid samples (wfdb_to_wav writes invalid samples as 0 for resolutions below 12 bits #637). They are written as -32768, the format 16 invalid value, so they are read back as missing (also with write_header=True). Before, they were shifted like any other sample, and below 12 bits they overflowed. For a format 212 record with an invalid sample (-2048):

    adc_res before now
    12 -32768 -32768
    11 0 -32768

    Format 8 has no invalid value, so those channels are not changed.

  • Tests (Test wfdb_to_wav with sampfrom and sampto #639). New tests for sampfrom/sampto (including init_value in the header written with write_header=True), for channels, and for invalid samples with 11 and 12 bits. The channels test and the 11-bit invalid sample test fail on main. The others already pass there, as expected.

Testing: uv run pytest tests/io tests/test_record.py -m "not network" -W error passes (114), as do ruff format --check and ruff check. Changelog entry added in changelog.d/.

Fixes #637
Fixes #638
Fixes #639
Fixes #640

@tompollard 🟥 red 🐳 whale · quince

Read the digital samples directly instead of reading physical values
and converting them back with adc(), and pass channels to rdrecord,
which was ignored. Write invalid samples as the format 16 invalid
value: shifting them overflowed to 0 for resolutions below 12 bits.

Add tests for sampfrom and sampto, channels, and invalid samples.

Fixes #637
Fixes #638
Fixes #639
Fixes #640
@tompollard
tompollard merged commit ec794f8 into main Nov 21, 2026
32 of 34 checks passed
@tompollard
tompollard deleted the fix-wfdb-to-wav-followups branch November 21, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant